trait Logger {
  def log(message: String): Unit
}

class Calculator extends Logger {
  override def log(message: String): Unit = {
    println(message + "记录到日志中")
  }

  def add(x: Int, y: Int): Int = {
    var add_result = x + y
    log(add_result.toString())
    return add_result
  }
  def subtract(x: Int, y: Int): Int = {
    var sub_result = x - y
    log(sub_result.toString())
    return sub_result
  }
}

var c = new Calculator()
c.add(10, 5)
c.subtract(10, 5)
